package com.leyantech.ecp.agenx.web;

import com.leyantech.ecp.agenx.common.config.Constants;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.google.gson.annotations.SerializedName;
import io.vertx.core.json.JsonObject;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author dongxu.ma, {@literal <dongxu.ma@leyantech.com>}
 * @date 2020-12-16.
 */
@Data
public class AuthMessage {

  // 客户端类型 web ，pc
  @JsonAlias("client_type")
  @SerializedName("client_type")
  private String clientType;

  @JsonAlias("store_id")
  @SerializedName("store_id")
  private String storeId;

  @JsonAlias("assistant_id")
  @SerializedName("assistant_id")
  private String assistantId;

  @JsonAlias("assistant_name")
  @SerializedName("assistant_name")
  private String assistantName;

  @JsonAlias("client_version")
  @SerializedName("client_version")
  private String clientVersion;

  @JsonAlias("client_uuid")
  @SerializedName("client_uuid")
  private String clientUuid;

  public static String check(JsonObject body) {
    final String blankFields = Stream.of(
        Constants.STORE_ID_FIELD,
        Constants.ASSISTANT_ID_FIELD,
        "assistant_name",
        "client_version",
        "client_uuid"
    )
        .filter(key -> StringUtils.isBlank(body.getString(key)))
        .collect(Collectors.joining(","));
    if (blankFields.isEmpty()) {
      return "";
    }
    return blankFields + " must not be blank.";
  }

}
